from django.contrib.syndication.feeds import Feed
from models import Post, Forum, Topic

class LatestForum(Feed):
	def  get_objects(self, forum_id):
		return Forum.object.get(id=forum_id)

	def title(self, obj):
		return "Recent posts in %s" % obj.title

	def link(self, obj):
		return "/beastly/forums/" + obj.id + "/"

	def description(self, obj):
		return obj.description

	def items(self.obj):
		obj.post_set.order_by('added')[:20]

class LatestTopic(Feed):
	def  get_objects(self, topic_id):
		return Forum.object.get(id=topic_id)

	def title(self, obj):
		return "Recent posts in %s" % obj.title

	def link(self, obj):
		return "/beastly/forums/" + obj.id + "/"

	def description(self, obj):
		return "Recent posts to the topic: %s." % obj.title

	def items(self.obj):
		obj.post_set.order_by('added')[:20]
